package com.ashlikun.zxing.util

import android.graphics.PointF
import com.ashlikun.camera.scan.AnalyzeResult
import com.ashlikun.zxing.gray.GrayScaleDispatch
import com.google.zxing.Result
import com.google.zxing.ResultPoint

/**
 * 作者　　: 李坤
 * 创建时间: 2024/2/20　14:27
 * 邮箱　　：496546144@qq.com
 *
 * 功能介绍：工具
 */
object ScanUtils {
    /**
     * 灰度算法
     */
    fun hasDepencidesScale(): Boolean {
        try {
            Class.forName(GrayScaleDispatch::class.java.name)
        } catch (e: Exception) {
            return false
        } catch (e: Error) {
            return false
        }
        return true
    }

    /***
     * 二维码坐标转换屏幕坐标(旋转后)
     * @param point
     * @return
     */
    fun convertQRCodeToScreen(analyzeResult: AnalyzeResult<Result>) {
//        val scanRect = analyzeResult.scanRect
//        analyzeResult.resultAll.forEach { result ->
//            val point = result.resultPoints
//            if (!point.isNullOrEmpty()) {
//
//                val preX: Float = scanRect
//                val preY: Float = Config.scanRect.getPreY()
//                val extraX: Float = Config.scanRect.getExtraX()
//                val extraY: Float = Config.scanRect.getExtraY()
//                val aspeX: Float
//                val aspeY: Float
//                if (Config.is90() || Config.is270()) {
//                    aspeX = (preX + extraX) / Config.scanRect.getDataX() as Float
//                    aspeY = (preY + extraY) / Config.scanRect.getDataY() as Float
//                } else {
//                    aspeX = (preX + extraX) / Config.scanRect.getDataY() as Float
//                    aspeY = (preY + extraY) / Config.scanRect.getDataX() as Float
//                }
//                val pointFS = arrayOfNulls<PointF>(point.size)
//                for (i in point.indices) {
//                    var relatPointX: Float
//                    var relatPointY: Float
//                    if (Config.is90()) {
//                        relatPointX = (Config.scanRect.getScanR().left + point[i].y) * aspeX - extraX / 2
//                        relatPointY = (Config.scanRect.getScanR().top + point[i].x) * aspeY - extraY / 2
//                    } else if (Config.is270()) {
//                        relatPointX = preX - (Config.scanRect.getScanR().left + point[i].y) * aspeX + extraX / 2
//                        relatPointY = preY - (Config.scanRect.getScanR().top + point[i].x) * aspeY + extraY / 2
//                    } else {
//                        relatPointX = preX + extraX / 2 - (Config.scanRect.getScanR().top + point[i].x) * aspeX
//                        relatPointY = (Config.scanRect.getScanR().left + point[i].y) * aspeY - extraY / 2
//                    }
//                    pointFS[i] = PointF(relatPointX, relatPointY)
//                }
//            }
//        }
    }
}